package com.blast.apply.adapter

import android.view.View
import com.blast.apply.R
import com.chad.library.adapter.base.BaseViewHolder
import com.wxl.common.adapter.AbsKeyEventAdapter
import com.wxl.common.room.entity.UnApplyBlastEntity

class AuthDetailAdapter : AbsKeyEventAdapter<UnApplyBlastEntity.LgsBean.LgBean>{

    private var id:Int
    private var lan:String?=null
    val widths = ArrayList<Int>()

    constructor(data: List<UnApplyBlastEntity.LgsBean.LgBean>?,id:Int,lan:String?) : super(R.layout.item_auth_detail_layout,data){
        this.id = id
        this.lan = lan
    }

    override fun convert(helper: BaseViewHolder, item: UnApplyBlastEntity.LgsBean.LgBean) {
        super.convert(helper, item)

        if(this.widths.isNotEmpty()){
            setViewWidth(helper.getView(R.id.authDetailItemId)
                ,helper.getView(R.id.authDetailItemCode)
                ,helper.getView(R.id.authDetailItemLan)
                ,helper.getView(R.id.authDetailItemRemark))
        }

        item?.apply {
            helper.setText(R.id.authDetailItemId,id.toString())
            helper.setText(R.id.authDetailItemCode,uid)
            helper.setText(R.id.authDetailItemLan,lan)
            helper.setText(R.id.authDetailItemRemark,"有效")
        }
    }

    fun setWidths(widths: ArrayList<Int>) {
        this.widths.clear()
        this.widths.addAll(widths)
    }


    private fun setViewWidth(vararg vs: View) {
        (0 until vs.size).forEach { i ->
            vs[i].layoutParams.width = widths[i]
        }
    }
}